package com.liang.thread;

import com.liang.algorithm.Euclidean_metric;
import com.liang.pojo.User;
import com.liang.service.impl.UserCoordinationServiceImpl;
import com.liang.service.impl.UserServiceImpl;

import java.math.BigInteger;
import java.util.List;


//协同表1更新线程
public class ThreadB implements Runnable{
    private int userId=0;
    private User user=null;
    private List<User> userList=null;
    double distance=0;
    int i=0;//遍历数
    int temp=0;//存放user2的id
    private static boolean flag=true;

    //通过传进来的userId求得该user与其它user的距离
    public ThreadB(int userId) {
        this.userId=userId;
    }

    public void run() {
        UserServiceImpl userService = new UserServiceImpl();
        Euclidean_metric euclidean_metric = new Euclidean_metric();
        UserCoordinationServiceImpl ucs = new UserCoordinationServiceImpl();
        user = userService.getUser(userId);
        List<User> userList=userService.getUserList();
        for (User user2 : userList) {
            BigInteger user2Id= user2.getUserId();
            if(user.getUserId()!=user2Id){//排除自己跟自己比距离
                temp = user2Id.intValue();
                distance=euclidean_metric.euclidean_dis(user,user2);
            ucs.insertUserCoordinationMapper(userId,temp,distance);
            this.i +=1;
            }else {
                continue;
            }
        }
        flag=false;

    }
    //得到标志位
    public boolean getFlag(){
        return flag;
    }
}
